######################
#  Replication code for 'Mediating the Electoral Connection', forthcoming in the JOP
#  John Henderson and John Brooks
#  12/7/2015    
######################    

# figureVII.R
#  :: produces a descriptives table with imputation information

rm(list=ls())
setwd('~/Dropbox/rainReplication')

if(length(which(installed.packages()[,1]=='xtable'))!=1){
	install.packages('xtable')                        
}                  
library(xtable)        

fes.type=3 
non.missings = 4

source('prelimMain.R')

main_iv1_fe=ivreg(vote~as.factor(fe_id_num)+d_inc+
	dist_prev + midterm + pres_party + 
	black + construction + educ + 
	minc + farmer + forborn + gvtwkr + manuf + pop + unempld + 
	urban + retail + sos + gov + comp_cq + redistricted + 
	dose + dose_prv + vote_prv,
	~as.factor(fe_id_num)+d_inc+
	dist_prev + midterm + pres_party + 
	black + construction + educ + 
	minc + farmer + forborn + gvtwkr + manuf + pop + unempld + 
	urban + retail + sos + gov + comp_cq + redistricted + 
	dose_prv + vote_prv + rain_day+rain_day_prev,
	subset=full,data=covs)

ix=as.numeric(names(main_iv1_fe$res))
	
covs=covs_none[,-c(37)]   
is.naFun=function(x){
	return(length(which(!is.na(x))))
}

col1=apply(covs[full,],2,is.naFun)
col2=apply(covs[full,],2,mean,na.rm=T)
col3=apply(covs[full,],2,sd,na.rm=T)  
col4=1-apply(covs[ix,],2,is.naFun)/length(ix)     
   
xtable(digits=3,cbind(col1,col2,col3,col4)[c(2,4,9:28,5,7,6,8,1,3),])

# END      